package com.dj.mingkong.portal.biz.controller.music;

import com.dj.mingkong.common.annotation.RequestLimit;
import com.dj.mingkong.common.infrastructure.base.dto.rest.RestResponse;
import com.dj.mingkong.common.microservice.UserContext;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianAddVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianUpdateVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.MusicianVo;
import com.dj.mingkong.portal.biz.service.music.MusicianService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 音乐人管理
 *
 * @author zenglonghui
 * @date: 2022/8/20 19:59
 */
@RestController
@RequestMapping("/musician")
public class MusicianController {
    @Resource
    private MusicianService musicianService;

    /**
     * 音乐人申请
     *
     * @param addVo {}
     * @return Boolean
     */
    @PostMapping("/add")
    @RequestLimit(count = 2)
    public RestResponse<Boolean> insert(@RequestBody @Validated MusicianAddVo addVo) {
        musicianService.insert(addVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 音乐人修改
     *
     * @param updateVo {}
     * @return Boolean
     */
    @PostMapping("/updateById")
    @RequestLimit(count = 2)
    public RestResponse<Boolean> updateById(@RequestBody @Validated MusicianUpdateVo updateVo) {
        musicianService.updateById(updateVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 获取我的音乐人列表
     *
     * @return BoxVo
     */
    @GetMapping("/listMyMusician")
    public RestResponse<List<MusicianVo>> listMyMusician() {
        final List<MusicianVo> musicianVos = musicianService.listMyMusician(UserContext.getUserId());
        return RestResponse.success(musicianVos);
    }

    /**
     * 模糊搜索建议数据
     *
     * @param name String
     * @return String
     */
    /*@GetMapping("/searchLikeName/{name}")
    public RestResponse<List<String>> searchLikeName(@PathVariable(value = "name") String name) {
        if (StringUtils.isBlank(name)) {
            return RestResponse.success(Lists.newArrayList());
        }
        final SearchHits<MusicianEsEo> searchHits = musicianService.searchLikeName(name);
        final List<String> strings = searchHits.getSearchHits().stream().map(searchHit -> searchHit.getContent().getStageName()).toList();
        return RestResponse.success(strings);
    }*/

    /**
     * 分页搜索
     *
     * @param queryVo {}
     * @return MusicianVo
     */
   /* @PostMapping("/searchByVo")
    public RestResponse<PageVo<MusicianVo>> searchByVo(
            @RequestBody @Validated MusicianQueryEsVo queryVo) {
        PageVo<MusicianVo> pageVo = new PageVo<>();
        AssertUtils.checkQueryPageVo(queryVo);
        final SearchHits<MusicianEsEo> searchHits = musicianService.searchByVo(queryVo);
        pageVo.setTotal(searchHits.getTotalHits());
        final List<MusicianVo> musicianVoList = searchHits.getSearchHits().stream().map(searchHit ->
                SmartBeanCopy.copy(searchHit.getContent(), MusicianVo.class)
                        .setHighlightName(searchHit.getHighlightField("stageName").get(0))).toList();
        pageVo.setRecords(musicianVoList);
        return RestResponse.success(pageVo);
    }*/

}
